package edu.mse.camel.client.whiteboard.gef.ui.editpart;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ComponentEditPolicy;
import org.eclipse.gef.requests.GroupRequest;

import edu.mse.camel.client.whiteboard.gef.ui.commands.ShapeDeleteCommand;
import edu.mse.camel.client.whiteboard.gef.whiteboard.Shape;
import edu.mse.camel.client.whiteboard.gef.whiteboard.WhiteboardDiagram;

/**
 * This edit policy enables the removal of a Shapes instance from its container. 
 * @see ShapeEditPart#createEditPolicies()
 * @see ShapeTreeEditPart#createEditPolicies()
 * @author darpan
 */
class ShapeComponentEditPolicy extends ComponentEditPolicy {
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.ComponentEditPolicy#createDeleteCommand(org.eclipse.gef.requests.GroupRequest)
	 */
	protected Command createDeleteCommand(GroupRequest deleteRequest) {
		Object parent = getHost().getParent().getModel();
		Object child = getHost().getModel();
		if (parent instanceof WhiteboardDiagram && child instanceof Shape) {
			return new ShapeDeleteCommand((WhiteboardDiagram) parent, (Shape) child);
		}
		return super.createDeleteCommand(deleteRequest);
	}
}